'''

@author: wyndem
@Emil:   wyndem@qq.com
@FileName: authordao.py
@Time: 2019/3/11 17:51
@Software: PyCharm
@Description: 

'''
import copy
import time

from novel.dao import POOL


def findByNameAuthor(name):
    """
    通过笔名查询作者表中记录
    :param name:  笔名
    :return:
    """
    conn = POOL.connection()
    cursor = conn.cursor()
    sql = """
       SELECT * FROM `author` WHERE pen_name=%s
      """
    cursor.execute(sql, (name))
    data = cursor.fetchone()
    cursor.close()
    conn.close()
    return data

def insertAuthor(name):
    """
    插入外部作者
    :param name: 笔名
    :return:  插入后的id
    """
    conn = POOL.connection()
    cursor = conn.cursor()
    sql = """
           INSERT INTO `bookdb`.`author`(`pen_name`, `start_pen_date`) VALUES (%s, %s)
         """
    cursor.execute(sql,(name, int(time.time())))
    author_id = cursor.lastrowid
    conn.commit()
    id=copy.deepcopy(author_id)
    cursor.close()
    conn.close()
    return id

